/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.ScholarshipApplyMapper;
import cn.qidisoft.edu.hzjt.model.ScholarshipApply;
import cn.qidisoft.edu.hzjt.service.IScholarshipApplyService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 
 * @author hxq
 * @version $Id: ScholarshipApplyServiceImpl.java, v 0.1 2018年11月5日 下午10:03:34 hxq Exp $
 */
@Service("scholarshipApplyService")
public class ScholarshipApplyServiceImpl implements IScholarshipApplyService {
  private static final LoggerAdapter LOGGER =
      LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
  @Autowired
  private ScholarshipApplyMapper scholarshipApplyMapper;

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryScholarshipApplyPageList(cn.qidisoft.edu.hzjt.model.ScholarshipApply,
   *      cn.qidisoft.core.common.pagination.Page)
   */
  @Override
  public PaginationBean<ScholarshipApply> queryScholarshipApplyPageList(
      ScholarshipApply scholarshipApply, Page page) {
    try {
      int c = scholarshipApplyMapper.queryScholarshipApplyPageCount(scholarshipApply);
      int totalRecords = 0;
      totalRecords = (int) c;
      PaginationBean<ScholarshipApply> pageHolder =
          new PaginationBean<ScholarshipApply>(page, totalRecords);
      List<ScholarshipApply> resultList =
          scholarshipApplyMapper.queryScholarshipApplyPageList(scholarshipApply,
              new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                  pageHolder.getPageSize()));
      pageHolder.setPageList(resultList);
      return pageHolder;
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryScholarshipApplyPageList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), ToStringBuilder.reflectionToString(
              scholarshipApply + "===" + page, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryVerifyLevelScholarshipCout(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public int queryVerifyLevelScholarshipCout(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.queryVerifyLevelScholarshipCout(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryVerifyLevelScholarshipCout [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryVerifyScoreScholarshipCount(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public int queryVerifyScoreScholarshipCount(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.queryVerifyScoreScholarshipCount(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryVerifyScoreScholarshipCount [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryVerifyPXXMScholarshipCount(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public int queryVerifyPXXMScholarshipCount(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.queryVerifyPXXMScholarshipCount(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryVerifyPXXMScholarshipCount [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryVerifyisExistScoreScholarshipCount(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public int queryVerifyisExistScoreScholarshipCount(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.queryVerifyisExistScoreScholarshipCount(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryVerifyisExistScoreScholarshipCount [{}] error," + this.getClass().getName()
              + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#addStudentScholarship(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  @Transactional
  public int addStudentScholarship(ScholarshipApply scholarshipApply) {
    try {
      scholarshipApplyMapper.insert(scholarshipApply);
      return scholarshipApply.getSqid();
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("addStudentScholarship [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryGidByScholarshipApply(java.lang.String)
   */
  @Override
  public ScholarshipApply queryGidByScholarshipApply(String gid) {
    try {
      return scholarshipApplyMapper.queryGidByScholarshipApply(gid);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("queryGidByScholarshipApply [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(gid, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#modiftyStudentScholarship(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  @Transactional
  public int modiftyStudentScholarship(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.updateByPK(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("modiftyStudentScholarship [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#removeStudentScholarship(java.lang.String[])
   */
  @Override
  @Transactional
  public int removeStudentScholarship(String[] ids) {
    try {
      int count = 0;
      for (String id : ids) {
        scholarshipApplyMapper.deleteByPK(Integer.parseInt(id));
        count++;
      }
      return count;
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("removeStudentScholarship [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(ids, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryByScholarshipApplyPk(java.lang.Integer)
   */
  @Override
  public ScholarshipApply queryByScholarshipApplyPk(Integer id) {
    try {
      return scholarshipApplyMapper.queryByPK(id);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("queryByScholarshipApplyPk [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(id, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#submitStudentScholarship(java.lang.Integer)
   */
  @Override
  public int submitStudentScholarship(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.submitStudentScholarship(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("submitStudentScholarship [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryRepByScholarshipCout(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public int queryRepByScholarshipCout(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.queryRepByScholarshipCout(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("queryRepByScholarshipCout [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryScholarshipApplyAuditPageList(cn.qidisoft.edu.hzjt.model.ScholarshipApply,
   *      cn.qidisoft.core.common.pagination.Page)
   */
  @Override
  public PaginationBean<ScholarshipApply> queryScholarshipApplyAuditPageList(
      ScholarshipApply scholarshipApply, Page page) {
    try {
      int c = scholarshipApplyMapper.queryScholarshipApplyAuditPageCount(scholarshipApply);
      int totalRecords = 0;
      totalRecords = (int) c;
      PaginationBean<ScholarshipApply> pageHolder =
          new PaginationBean<ScholarshipApply>(page, totalRecords);
      List<ScholarshipApply> resultList =
          scholarshipApplyMapper.queryScholarshipApplyAuditPageList(scholarshipApply,
              new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                  pageHolder.getPageSize()));
      pageHolder.setPageList(resultList);
      return pageHolder;
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryScholarshipApplyAuditPageList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), ToStringBuilder.reflectionToString(
              scholarshipApply + "===" + page, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryScholarshipApplyAuditPK(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public ScholarshipApply queryScholarshipApplyAuditPK(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.queryScholarshipApplyAuditPK(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("queryScholarshipApplyAuditPK [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#auditStudentScholarship(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public int auditStudentScholarship(ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.auditStudentScholarship(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("auditStudentScholarship [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryScholarshipApplyManagerPageList(cn.qidisoft.edu.hzjt.model.ScholarshipApply,
   *      cn.qidisoft.core.common.pagination.Page)
   */
  @Override
  public PaginationBean<ScholarshipApply> queryScholarshipApplyManagerPageList(
      ScholarshipApply scholarshipApply, Page page) {
    try {
      int c = scholarshipApplyMapper.queryScholarshipApplyManagerPageCount(scholarshipApply);
      int totalRecords = 0;
      totalRecords = (int) c;
      PaginationBean<ScholarshipApply> pageHolder =
          new PaginationBean<ScholarshipApply>(page, totalRecords);
      List<ScholarshipApply> resultList =
          scholarshipApplyMapper.queryScholarshipApplyManagerPageList(scholarshipApply,
              new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                  pageHolder.getPageSize()));
      pageHolder.setPageList(resultList);
      return pageHolder;
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryScholarshipApplyManagerPageList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), ToStringBuilder.reflectionToString(
              scholarshipApply + "====" + page, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#queryClassByScholarshipapplyReport(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public List<ScholarshipApply> queryClassByScholarshipapplyReport(
      ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.queryClassByScholarshipapplyReport(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "queryClassByScholarshipapplyReport [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IScholarshipApplyService#exportScholarshipApplyManagerList(cn.qidisoft.edu.hzjt.model.ScholarshipApply)
   */
  @Override
  public List<ScholarshipApply> exportScholarshipApplyManagerList(
      ScholarshipApply scholarshipApply) {
    try {
      return scholarshipApplyMapper.exportScholarshipApplyManagerList(scholarshipApply);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "exportScholarshipApplyManagerList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(scholarshipApply, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

}
